package com.acme.bankapp.service;

import java.util.Scanner;
import java.util.StringTokenizer;
/**
 * The class StringParse methods are created for parsing string of data argClient into needed data.
 * @author Troitskaya Anastasia
 */
import com.acme.bankapp.domain.Gender;
public class StringParse {
	String accountType;
	double balance;
	double overDraft;
	String firstName;
	String lastName;
	String gender;
	StringTokenizer strToken;
	StringParse(String argClient) {
		strToken = new StringTokenizer(argClient, ";");
	}
	String getAccountType() {
		String helpString = strToken.nextToken();
		@SuppressWarnings("resource")
		Scanner s = new Scanner(helpString).useDelimiter("accounttype=");
		return s.next();
	}
	double getBalance() {
		String helpString = strToken.nextToken();
		@SuppressWarnings("resource")
		Scanner s = new Scanner(helpString).useDelimiter("balance=");
		return s.nextDouble();
	}
	double getOverDraft() {
		String helpString = strToken.nextToken();
		@SuppressWarnings("resource")
		Scanner s = new Scanner(helpString).useDelimiter("overdraft=");
		return s.nextDouble();
	}
	String getFirstName() {
		String helpString = strToken.nextToken();
		@SuppressWarnings("resource")
		Scanner s = new Scanner(helpString).useDelimiter("firstname=");
		return s.next();
	}
	String getLastName() {
		String helpString = strToken.nextToken();
		@SuppressWarnings("resource")
		Scanner s = new Scanner(helpString).useDelimiter("lastname=");
		return s.next();
	}
	Gender getGender() {
		String helpString = strToken.nextToken();
		@SuppressWarnings("resource")
		Scanner s = new Scanner(helpString).useDelimiter("gender=");
		String g = s.next();
		if (g.equals("m"))
			return Gender.MALE;
		else
			if (g.equals("f"))
			return Gender.FEMALE;
		return null;
	}
}
